﻿using System;
using Internal.Runtime.Services.BattleSkill;
using Runtime.Models;
using Runtime.Services.Battle.Entity;
using UnityEngine;

namespace Runtime.Services.BattleSkill {

    /// <summary>
    /// 战斗效果维持者
    /// </summary>
    public interface IDFR_BattleEffectHolder {

        IDFR_BattleEffectHolderSetter AsSetter();

        /// <summary>
        /// 实体句柄
        /// </summary>
        DFR_BattleEntityHandle EntityHandle { get; }

        /// <summary>
        /// 模型资产键
        /// </summary>
        string ModelAssetKey { get; }

        /// <summary>
        /// 是否有模型资产
        /// </summary>
        bool HasModelAsset { get; }

        /// <summary>
        /// 是否需要同步显示位置
        /// </summary>
        bool RequireSyncPosition { get; }
    }

    public interface IDFR_BattleEffectHolderSetter {

        /// <summary>
        /// 设置模型资产键
        /// </summary>
        /// <param name="value">值</param>
        void SetModelAssetKey(string value);

        /// <summary>
        /// 同步位置
        /// </summary>
        /// <param name="entityInstanceID">需要保持同步的实体实例ID</param>
        void SyncPositionFrom(DFR_BattleEntityInstanceID entityInstanceID);

        /// <summary>
        /// 同步一次位置
        /// </summary>
        /// <param name="entityInstanceID">需要同步的实体实例ID</param>
        void SyncPositionOnce(DFR_BattleEntityInstanceID entityInstanceID);
    }

    public abstract class DFR_BattleEffectHolder : DFR_Entity, IDFR_BattleEffectHolder, IDFR_BattleEffectHolderSetter, IDFR_BattleEffectHolderInternal {

        public IDFR_BattleEffectHolderSetter AsSetter() => this;

        public DFR_BattleEntityHandle EntityHandle { get; private set; }

        public string ModelAssetKey { get; private set; }

        public bool HasModelAsset { get; private set; }

        public void SetModelAssetKey(string value) {
            ModelAssetKey = value;
            HasModelAsset = IDFR_BattleEffectModelBase.MODEL_ASSET_REGEXP.IsMatch(value);
        }

        bool IDFR_BattleEffectHolder.RequireSyncPosition => false;
        void IDFR_BattleEffectHolderSetter.SyncPositionFrom(DFR_BattleEntityInstanceID entityInstanceID) => throw new NotSupportedException("源数据有静态实现，不参与表现");
        void IDFR_BattleEffectHolderSetter.SyncPositionOnce(DFR_BattleEntityInstanceID entityInstanceID) => throw new NotSupportedException("源数据有静态实现，不参与表现");
        Vector3 IDFR_BattleEffectHolderInternal.SyncPosition() => throw new NotSupportedException("源数据有静态实现，不参与表现");

        void IDFR_BattleEffectHolderInternal.SetEntityHandle(DFR_BattleEntityHandle value) => EntityHandle = value;
    }
}

namespace Internal.Runtime.Services.BattleSkill {

    public interface IDFR_BattleEffectHolderInternal {

        void SetEntityHandle(DFR_BattleEntityHandle value);

        Vector3 SyncPosition();
    }
}
